<!-- HTML header for doxygen 1.8.8-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!-- For Mobile Devices -->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
        <meta name="generator" content="Doxygen 1.8.18"/>
        <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <title>HElib: /HElib/include/helib/assertions.h Source File</title>
        <!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
        <script type="text/javascript" src="dynsections.js"></script>
        <link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
        <link href="doxygen.css" rel="stylesheet" type="text/css" />
        <link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
        <link href='https://fonts.googleapis.com/css?family=Roboto+Slab' rel='stylesheet' type='text/css'>
		<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,100;1,700&family=Merriweather&family=Merriweather+Sans&family=Open+Sans&family=Poppins:ital@1&family=Roboto:ital,wght@0,400;1,300;1,900&display=swap" rel="stylesheet"> 
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
        <link href="jquery.smartmenus.bootstrap.css" rel="stylesheet">
        <script type="text/javascript" src="jquery.smartmenus.js"></script>
        <!-- SmartMenus jQuery Bootstrap Addon -->
        <script type="text/javascript" src="jquery.smartmenus.bootstrap.js"></script>
        <!-- SmartMenus jQuery plugin -->
    </head>
    <body style="font-family: 'Merriweather', serif;">
        <nav class="navbar navbar-default" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand">HElib Implementing Homomorphic Encryption</a>
                </div>
            </div>
        </nav>
        <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
            <div class="content" id="content">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12 panel " style="padding-bottom: 15px;">
                            <div style="margin-bottom: 15px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_d0c4ae63660968bf6b1c77a1e8aecf95.html">helib</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">assertions.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="assertions_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/* Copyright (C) 2019-2020 IBM Corp.</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * This program is Licensed under the Apache License, Version 2.0</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> * (the &quot;License&quot;); you may not use this file except in compliance</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * with the License. You may obtain a copy of the License at</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> *   http://www.apache.org/licenses/LICENSE-2.0</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * Unless required by applicable law or agreed to in writing, software</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> * See the License for the specific language governing permissions and</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * limitations under the License. See accompanying LICENSE file.</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160; </div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment">// Header guard</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#ifndef HELIB_ASSERTIONS_H</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="preprocessor">#define HELIB_ASSERTIONS_H</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160; </div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="exceptions_8h.html">helib/exceptions.h</a>&gt;</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160; </div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacehelib.html">helib</a> {</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160; </div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> ExceptionTy = ::helib::LogicError, <span class="keyword">typename</span> T = <span class="keywordtype">void</span>&gt;</div>
<div class="line"><a name="l00061"></a><span class="lineno"><a class="line" href="namespacehelib.html#aca37b5e05bffd4550c995e83594d7325">   61</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#aca37b5e05bffd4550c995e83594d7325">assertTrue</a>(<span class="keyword">const</span> T&amp; value, <span class="keyword">const</span> std::string&amp; message)</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;{</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;  static_assert(std::is_base_of&lt;::helib::Exception, ExceptionTy&gt;::value,</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;                <span class="stringliteral">&quot;ExceptionTy must inherit from helib::Exception&quot;</span>);</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;  static_assert(std::is_same&lt;bool, T&gt;::value, <span class="stringliteral">&quot;Type T is not boolean&quot;</span>);</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;  <span class="keywordflow">if</span> (!value) {</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    <span class="keywordflow">throw</span> ExceptionTy(message);</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;  }</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;}</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160; </div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> ExceptionTy = ::helib::LogicError, <span class="keyword">typename</span> T = <span class="keywordtype">void</span>&gt;</div>
<div class="line"><a name="l00083"></a><span class="lineno"><a class="line" href="namespacehelib.html#ad5fc5ad34739ea66baa96f988dd07beb">   83</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#ad5fc5ad34739ea66baa96f988dd07beb">assertFalse</a>(T value, <span class="keyword">const</span> std::string&amp; message)</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;{</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;  static_assert(std::is_same&lt;bool, T&gt;::value, <span class="stringliteral">&quot;Type T is not boolean&quot;</span>);</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;  static_assert(std::is_base_of&lt;::helib::Exception, ExceptionTy&gt;::value,</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;                <span class="stringliteral">&quot;ExceptionTy must inherit from helib::Exception&quot;</span>);</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;  <span class="keywordflow">if</span> (value) {</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    <span class="keywordflow">throw</span> ExceptionTy(message);</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;  }</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;}</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160; </div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> ExceptionTy = ::helib::LogicError, <span class="keyword">typename</span> T = <span class="keywordtype">void</span>&gt;</div>
<div class="line"><a name="l00108"></a><span class="lineno"><a class="line" href="namespacehelib.html#aec77ae5fa0fd11a0a42e07fefe49b99d">  108</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#aec77ae5fa0fd11a0a42e07fefe49b99d">assertEq</a>(<span class="keyword">const</span> T&amp; a, <span class="keyword">const</span> T&amp; b, <span class="keyword">const</span> std::string&amp; message)</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;{</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;  static_assert(std::is_base_of&lt;::helib::Exception, ExceptionTy&gt;::value,</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;                <span class="stringliteral">&quot;ExceptionTy must inherit from helib::Exception&quot;</span>);</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;  <span class="keywordtype">bool</span> value = a == b;</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;  <span class="keywordflow">if</span> (!value) {</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;    <span class="keywordflow">throw</span> ExceptionTy(message);</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;  }</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;}</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160; </div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> ExceptionTy = ::helib::LogicError, <span class="keyword">typename</span> T = <span class="keywordtype">void</span>&gt;</div>
<div class="line"><a name="l00133"></a><span class="lineno"><a class="line" href="namespacehelib.html#acd5b530c0837ef9111dc4a361364d669">  133</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#acd5b530c0837ef9111dc4a361364d669">assertNeq</a>(<span class="keyword">const</span> T&amp; a, <span class="keyword">const</span> T&amp; b, <span class="keyword">const</span> std::string&amp; message)</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;{</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;  static_assert(std::is_base_of&lt;::helib::Exception, ExceptionTy&gt;::value,</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;                <span class="stringliteral">&quot;ExceptionTy must inherit from helib::Exception&quot;</span>);</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;  <span class="keywordtype">bool</span> value = a != b;</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;  <span class="keywordflow">if</span> (!value) {</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;    <span class="keywordflow">throw</span> ExceptionTy(message);</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;  }</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;}</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160; </div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> ExceptionTy = ::helib::LogicError, <span class="keyword">typename</span> T = <span class="keywordtype">void</span>&gt;</div>
<div class="line"><a name="l00156"></a><span class="lineno"><a class="line" href="namespacehelib.html#aa7b1da8169ee8b9a0ab221e4c67961c5">  156</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#aa7b1da8169ee8b9a0ab221e4c67961c5">assertNotNull</a>(<span class="keyword">const</span> T&amp; p, <span class="keyword">const</span> std::string&amp; message)</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;{</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;  static_assert(std::is_base_of&lt;::helib::Exception, ExceptionTy&gt;::value,</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;                <span class="stringliteral">&quot;ExceptionTy must inherit from helib::Exception&quot;</span>);</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;  <span class="keywordflow">if</span> (p == <span class="keyword">nullptr</span>) {</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;    <span class="keywordflow">throw</span> ExceptionTy(message);</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;  }</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;}</div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160; </div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> ExceptionTy = ::helib::OutOfRangeError, <span class="keyword">typename</span> T = <span class="keywordtype">void</span>&gt;</div>
<div class="line"><a name="l00183"></a><span class="lineno"><a class="line" href="namespacehelib.html#a8e36344202aac3b245f5ba71f69a3e8b">  183</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#a8e36344202aac3b245f5ba71f69a3e8b">assertInRange</a>(<span class="keyword">const</span> T&amp; elem,</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;                          <span class="keyword">const</span> T&amp; min,</div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;                          <span class="keyword">const</span> T&amp; max,</div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;                          <span class="keyword">const</span> std::string&amp; message,</div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;                          <span class="keywordtype">bool</span> right_inclusive = <span class="keyword">false</span>)</div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;{</div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;  static_assert(std::is_base_of&lt;::helib::Exception, ExceptionTy&gt;::value,</div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;                <span class="stringliteral">&quot;ExceptionTy must inherit from helib::Exception&quot;</span>);</div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;  <span class="keywordtype">bool</span> min_less = min &lt;= elem;</div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;  <span class="keywordflow">if</span> (!min_less) {</div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;    <span class="keywordflow">throw</span> ExceptionTy(message);</div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;  }</div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;  <span class="keywordtype">bool</span> max_great = right_inclusive ? elem &lt;= max : elem &lt; max;</div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;  <span class="keywordflow">if</span> (!max_great) {</div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;    <span class="keywordflow">throw</span> ExceptionTy(message);</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;  }</div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;}</div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160; </div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;} <span class="comment">// namespace helib</span></div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;<span class="preprocessor">#endif // End of header guard</span></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="aexceptions_8h_html"><div class="ttname"><a href="exceptions_8h.html">exceptions.h</a></div><div class="ttdoc">Various HElib-specific exception types.</div></div>
<div class="ttc" id="anamespacehelib_html_aca37b5e05bffd4550c995e83594d7325"><div class="ttname"><a href="namespacehelib.html#aca37b5e05bffd4550c995e83594d7325">helib::assertTrue</a></div><div class="ttdeci">void assertTrue(const T &amp;value, const std::string &amp;message)</div><div class="ttdef"><b>Definition:</b> assertions.h:61</div></div>
<div class="ttc" id="anamespacehelib_html_aec77ae5fa0fd11a0a42e07fefe49b99d"><div class="ttname"><a href="namespacehelib.html#aec77ae5fa0fd11a0a42e07fefe49b99d">helib::assertEq</a></div><div class="ttdeci">void assertEq(const T &amp;a, const T &amp;b, const std::string &amp;message)</div><div class="ttdef"><b>Definition:</b> assertions.h:108</div></div>
<div class="ttc" id="anamespacehelib_html_a8e36344202aac3b245f5ba71f69a3e8b"><div class="ttname"><a href="namespacehelib.html#a8e36344202aac3b245f5ba71f69a3e8b">helib::assertInRange</a></div><div class="ttdeci">void assertInRange(const T &amp;elem, const T &amp;min, const T &amp;max, const std::string &amp;message, bool right_inclusive=false)</div><div class="ttdef"><b>Definition:</b> assertions.h:183</div></div>
<div class="ttc" id="anamespacehelib_html_acd5b530c0837ef9111dc4a361364d669"><div class="ttname"><a href="namespacehelib.html#acd5b530c0837ef9111dc4a361364d669">helib::assertNeq</a></div><div class="ttdeci">void assertNeq(const T &amp;a, const T &amp;b, const std::string &amp;message)</div><div class="ttdef"><b>Definition:</b> assertions.h:133</div></div>
<div class="ttc" id="anamespacehelib_html_aa7b1da8169ee8b9a0ab221e4c67961c5"><div class="ttname"><a href="namespacehelib.html#aa7b1da8169ee8b9a0ab221e4c67961c5">helib::assertNotNull</a></div><div class="ttdeci">void assertNotNull(const T &amp;p, const std::string &amp;message)</div><div class="ttdef"><b>Definition:</b> assertions.h:156</div></div>
<div class="ttc" id="anamespacehelib_html"><div class="ttname"><a href="namespacehelib.html">helib</a></div><div class="ttdef"><b>Definition:</b> apiAttributes.h:21</div></div>
<div class="ttc" id="anamespacehelib_html_ad5fc5ad34739ea66baa96f988dd07beb"><div class="ttname"><a href="namespacehelib.html#ad5fc5ad34739ea66baa96f988dd07beb">helib::assertFalse</a></div><div class="ttdeci">void assertFalse(T value, const std::string &amp;message)</div><div class="ttdef"><b>Definition:</b> assertions.h:83</div></div>
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.18
</small></address>
</body>
        <script type="text/javascript" src="doxy-boot.js"></script>
</html>
